const fs = require('fs')
const path = require('path')

// console.log(__filename)

function calculateFileSize(readDir) {
    const dirPath = path.resolve(__dirname, readDir)
    console.log(dirPath)
    let totalSize = 0
    const files = fs.readdirSync(dirPath)
    files.forEach((file) => {
        const fileDir = path.join(dirPath, file)
        const statObj = fs.statSync(fileDir);
        if (statObj.isFile()) {
            totalSize += statObj.size
        } else {
            totalSize += calculateFileSize(fileDir)
        }
    });

    return totalSize
}

const fileSize = calculateFileSize('../part5')
console.log(fileSize)